<template>
	<view style="width: 100%; ">
		<!-- 搜索栏 -->
		<!-- 	<view style="width: 702rpx;height: 50rpx;border-radius: 25rpx;background-color: #F5F5F5; display: flex;align-items: center;margin-top: 30rpx;">
			<image mode="aspectFill" src="../../static/home/search.png" style="width: 34rpx;height: 34rpx;margin-left: 49rpx;"></image>
			<view style="width: 1px;height: 32rpx;background-color: #E0E0E0;margin-left: 28rpx;"></view>
			<input placeholder="搜索预约人 联系方式" placeholder-class="inputclass" confirm-type="search" style="margin-left: 31rpx;font-size: 24rpx;" />
		</view> -->

		<!-- 滑动模块 -->
		<scroll-view v-if="group_id == 1" :enable-flex="true" :show-scrollbar="false" @scrolltolower="lower"
			:scroll-y="true" style="width: 100%; display: flex;flex-direction: column; align-items: center;flex: auto;">
			<view v-for="(item,index) in stafforder" :key="index"
				style="width: 100%; margin-top: 19rpx;display: flex;flex-direction: column;justify-content: center;align-items: center;">
				<!-- 分割线 -->
				<view style="width: 100%;height: 10rpx;background-color: #F7F8FF;"></view>
				<!-- 订单item -->
				<view
					style="width: 702rpx; display: flex;flex-direction: column;justify-content: center;align-items: center;margin-top: 19rpx;">
					<!-- 订单号 -->
					<text style="font-size: 24rpx;color: #333333;align-self: flex-end;">
						订单号：{{item.order_sn}}
					</text>
					<!-- 分割线 -->
					<view style="width: 100%;height: 1px;background-color: #F7F8FF;margin-top: 20rpx;"></view>
					<!-- 订单信息item -->
					<view
						style="width: 702rpx; display: flex;justify-content: space-between;align-items: center;margin-top: 19rpx;">
						<view class="order_show show_a">
							<text>预约时间:</text>
							<text>预约人:</text>
							<text>联系方式:</text>
							<text>预约类型:</text>
							<text>当前状态:</text>
						</view>
						<view class="order_show show_b">
							<text>{{item.yuyueshijian}}</text>
							<text>{{item.consignee}}</text>
							<text>{{item.phone}}</text>
							<text>{{item.item[0].goods_title}}</text>
							<text v-for="(item1, index ) in item.item" :key="index">
								<!-- <view v-for="(item1, index ) in item.item" :key="index"> -->
								<text v-if="item1.aftersale_status == '-1' ">拒绝</text>
								<text v-if="item1.aftersale_status == '0' ">未申请</text>
								<text v-if="item1.aftersale_status == '1' ">申请售后</text>
								<text v-if="item1.aftersale_status == '2' ">售后完成</text>
								<!-- </view> -->
							</text>
						</view>
					</view>
					<!-- 分割线 -->
					<view style="width: 100%;height: 1px;background-color: #F7F8FF;margin-top: 20rpx; ">

					</view>

					<!-- 按钮区域 -->
					<view
						style="display: flex;align-items: center;font-size: 24rpx;color: #FFFFFF;margin-top: 19rpx;justify-content: space-between;width: 100%;">
						<!-- 	<view style="width: 150rpx;height: 60rpx;background-color: #4B9EFF;text-align: center;line-height: 60rpx;margin-right: 27rpx;"     @click="GO('writeOff',item)" v-show="group_id !== 1">立即核销</view> -->
						<!-- <block v-for="(item1, index ) in item" :key="index"> -->
						<!-- <view v-for="(item1, index ) in item.item" :key="index">
							<view style="padding: 10rpx 20rpx;background-color: #F07203;"
								v-if="item1.aftersale_status == '-1' ">拒绝</view>
							<view style="padding: 10rpx 20rpx;background-color: #F07203;"
								v-if="item1.aftersale_status == '0' ">未申请</view>
							<view style="padding: 10rpx 20rpx;background-color: #F07203;"
								v-if="item1.aftersale_status == '1' ">申请售后</view>
							<view style="padding: 10rpx 20rpx;background-color: #F07203;"
								v-if="item1.aftersale_status == '2' ">售后完成</view>
						</view> -->
						<view class="radius"
							style="width: 150rpx;height: 60rpx;background-color: #F07203;text-align: center;line-height: 60rpx; border-radius: 5rpx;"
							@click="cancel(item)">
							
							申请退款
						</view>
						<text class=""></text>
						<!-- </block> -->
					</view>
				</view>
			</view>
			<!-- 让最下面的数据不要顶到底部，给点空间，美观一点 -->
			<text style="height: 50rpx;margin-top: 20rpx;font-size: 24rpx;color: #eeeeee;">加载数据</text>

		</scroll-view>


		<scroll-view v-else :enable-flex="true" :show-scrollbar="false" @scrolltolower="lower" :scroll-y="true"
			style="width: 100%; display: flex;flex-direction: column; align-items: center;flex: auto;">
			<view v-for="(item,index) in staffOrders" :key="index"
				style="width: 100%; margin-top: 19rpx;display: flex;flex-direction: column;justify-content: center;align-items: center;">
				<view style="width: 100%;height: 10rpx;background-color: #F7F8FF;"></view>
				<view
					style="width: 702rpx; display: flex;flex-direction: column;justify-content: center;align-items: center;margin-top: 19rpx;">
					<text style="font-size: 24rpx;color: #333333;align-self: flex-end;">
						订单号：{{item.order_sn}}
					</text>
					<view style="width: 100%;height: 1px;background-color: #F7F8FF;margin-top: 20rpx;"></view>
					<view
						style="width: 702rpx; display: flex;justify-content: space-between;align-items: center;margin-top: 19rpx;">
						<view class="order_show show_a">
							<text>预约时间:</text>
							<text>预约人:</text>
							<text>联系方式:</text>
							<text>预约类型:</text>
						</view>
						<view class="order_show show_b">
							<text>{{item.yuyueshijian}}</text>
							<text>{{item.consignee}}</text>
							<text>{{item.phone}}</text>
							<text>{{item.item[0].goods_title}}</text>
						</view>
					</view>
					<view style="width: 100%;height: 1px;background-color: #F7F8FF;margin-top: 20rpx;"></view>
					<view
						style="align-self: flex-end;display: flex;justify-content: center;align-items: center;font-size: 24rpx;color: #FFFFFF;margin-top: 19rpx;">
						<view
							style="width: 150rpx;height: 60rpx;background-color: #4B9EFF;text-align: center;line-height: 60rpx;margin-right: 27rpx;"
							@click="GO('writeOff',item)" v-show="type === 'nopay' ">立即核销</view>
						<view
							style="width: 150rpx;height: 60rpx;background-color: #F07203;text-align: center;line-height: 60rpx;"
							@click="cancel(item)" v-show="type === 'nopay'">取消订单</view>
					</view>
				</view>
			</view>
			<!-- 让最下面的数据不要顶到底部，给点空间，美观一点 -->
			<text style="height: 50rpx;margin-top: 20rpx;font-size: 24rpx;color: #eeeeee;">加载数据</text>

		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				group_id: '', //获取用户权限，控制核销开关
				type: '',
				stafforder: [], //普通用户
				staffOrders: [], //员工
				orderList: [{
					orderNumber: 'ABC123568974512385462892563245',
					orderContext: [{
							title: '预约时间：',
							context: '2021-01-15 14:38:25'
						},
						{
							title: '预约人：',
							context: '不知道你叫啥'
						},
						{
							title: '联系方式：',
							context: '13622020022'
						},
						{
							title: '预约类型：',
							context: '服务/洗车'
						}
					]
				}, ],
				page: 1,

			}
		},
		onLoad() {
			this.employees();
			this.group_id = uni.getStorageSync('group_id') //进页面获取员工但是用户身份
			this.type = this.$Route.query.type; //我的页面携带的参数，决定订单状态
			console.log('this.typethis.typethis.type', this.group_id)
		},
		onShow() {

			console.log('this.getStorageSync', this.group_id)

			this.staffOrder();
		},
		methods: {
			GO(type, item) {
				// this.staffOrder();
				this.$Router.push({
					name: type,
					params: {
						item: item
					}
				})
			},
			async cancel(item) {
				console.log(item)
				const res = await this.$request.post('addons/shopro/order_aftersale/aftersale', {
					data: {
						order_id: item.item[0].order_id,
						type: 'refund',
						order_item_id: item.item[0].id,
						phone: item.phone,
						content: '1',
						reason: '1',
						images: ' ',
					}
				})
				console.log('res', res)
				
				uni.$showMsg(res.data.msg) 


				// let res;
				// try{
				// 	res = await this.$request.post('addons/shopro/order/cancel',{
				// 		data:{
				// 			id:item.id
				// 		}
				// 	})
				// }catch(e) {
				// 	console.log('e :>> ', e);
				// 	return uni.showToast({
				// 		title:'网络链接失败',
				// 		icon:'icon'
				// 	})
				// }
				// this.staffOrder();
				// // this.employees();
				// this.$forceUpdate();
			},
			lower() {
				console.log("滑动到了页面底部")
			},
			// 用户订单展示 非员工
			async staffOrder() {



				try {
					let res = await this.$request.get('addons/shopro/order/index', {
						data: {
							type: 'nosend',
							page: this.page,
						}
					})

					if (group_id == 2) {
						// 如果是员工单，调取接口
						this.employees();
					}
					this.stafforder = res.data.data.data;
					this.$forceUpdate();
					console.log("this.stafforder: ", this.stafforder);
					console.log("res: ", res);

				} catch (e) {
					//TODO handle the exception
					return uni.showToast({
						title: '网络连接失败',
						icon: 'none'
					});
				}
				let group_id = uni.getStorageSync('group_id');

			},
			// 员工订单
			async employees() {
				let res;
				try {
					res = await this.$request.post('addons/shopro/staff/order', {
						data: {
							type: 'nosend',
							page: this.page,
						}
					})
				} catch (e) {
					console.log("e: ", e);
					//TODO handle the exception
					return uni.showToast({
						title: '网络连接失败',
						icon: 'none'
					});
				}
				this.staffOrders = res.data.data;
				// this.staffOrder();
				this.$forceUpdate();
				console.log("this.stafforder: ", this.stafforder);
				console.log("res: ", res);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.order_show {
		display: flex;
		flex: 1;
		flex-direction: column;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;

		&:first-child {
			color: #666;
		}

		&:last-child {
			color: #333;
		}

		>text {
			line-height: 1.6;
		}
	}
</style>
